<?php

namespace app\admin\model\csmwj;

use think\Model;


class Papercfg extends Model
{

    

    

    // 表名
    protected $name = 'csmwj_paper';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'locales_text',
        'cfghasdatelimit_text',
        'cfgbegintime_text',
        'cfgendtime_text',
        'cfghastimelimit_text',
        'cfgdisplayscore_text',
        'status_text',
        'themebannertype_text',
        'themetitleshow_text',
        'themequestionnoshow_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getLocalesList()
    {
        return ['zh' => __('Locales zh'), 'en' => __('Locales en')];
    }

    public function getCfghasdatelimitList()
    {
        return ['Y' => __('Cfghasdatelimit y'), 'N' => __('Cfghasdatelimit n')];
    }

    public function getCfghastimelimitList()
    {
        return ['Y' => __('Cfghastimelimit y'), 'N' => __('Cfghastimelimit n')];
    }

    public function getCfgdisplayscoreList()
    {
        return ['Y' => __('Cfgdisplayscore y'), 'N' => __('Cfgdisplayscore n')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden'), 'draft' => __('Draft')];
    }

    public function getThemebannertypeList()
    {
        return ['EMPTY' => __('Themebannertype empty'), 'STRING' => __('Themebannertype string'), 'IMAGE' => __('Themebannertype image'), 'IMAGES' => __('Themebannertype images')];
    }

    public function getThemetitleshowList()
    {
        return ['Y' => __('Themetitleshow y'), 'N' => __('Themetitleshow n')];
    }

    public function getThemequestionnoshowList()
    {
        return ['Y' => __('Themequestionnoshow y'), 'N' => __('Themequestionnoshow n')];
    }


    public function getLocalesTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['locales']) ? $data['locales'] : '');
        $list = $this->getLocalesList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCfghasdatelimitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cfghasdatelimit']) ? $data['cfghasdatelimit'] : '');
        $list = $this->getCfghasdatelimitList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCfgbegintimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cfgbegintime']) ? $data['cfgbegintime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCfgendtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cfgendtime']) ? $data['cfgendtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCfghastimelimitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cfghastimelimit']) ? $data['cfghastimelimit'] : '');
        $list = $this->getCfghastimelimitList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCfgdisplayscoreTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cfgdisplayscore']) ? $data['cfgdisplayscore'] : '');
        $list = $this->getCfgdisplayscoreList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getThemebannertypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['themebannertype']) ? $data['themebannertype'] : '');
        $list = $this->getThemebannertypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getThemetitleshowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['themetitleshow']) ? $data['themetitleshow'] : '');
        $list = $this->getThemetitleshowList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getThemequestionnoshowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['themequestionnoshow']) ? $data['themequestionnoshow'] : '');
        $list = $this->getThemequestionnoshowList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setCfgbegintimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCfgendtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
